#ifndef _WORK_CHANNEL_954B90DE_3503_4C3D_B381_A23C60AA7C0E_
#define _WORK_CHANNEL_954B90DE_3503_4C3D_B381_A23C60AA7C0E_
#pragma once
#include "base/memory/weak_ptr.h"
#include "ipc/ipc_message.h"

namespace dl {

class WorkChannel;

// 消息传递接口
struct MessageTransfer {
  /**
   * IPC消息分派
   * @param channel指示消息的管道来源
   * @param message消息结构
   * @return 返回是否已经处理
   */
  virtual bool OnMessageDispatch(WorkChannel* channel, const IPC::Message& message) = 0;
};

// 连接传递接口
struct ConnectTransfer {
  /**
   * 连接到来时通知
   * @param channel指示连接的管道来源
   * @param peer_pid指示发起连接的进程ID
   */
  virtual void OnConnectArrived(WorkChannel* channel, int32 peer_pid) = 0;
  /**
   * 当连接错误时通知
   * @param channel指示连接的管道来源
   */
  virtual void OnConnectError(WorkChannel* channel) = 0;
};

// 封装与外部进程通信的连接
class WorkChannel : public base::SupportsWeakPtr<WorkChannel> {
public:
	explicit WorkChannel(const std::string& name, MessageLoop* message_loop, 
      ConnectTransfer* connect_transfer, MessageTransfer* message_transfer);
	virtual ~WorkChannel();
  // 对等连接端的进程ID
  int32  PeerProcessID() const;
  // 发送消息
	void Send(IPC::Message* message);

private:
  struct Pimpl;
  scoped_ptr<Pimpl> pimpl_;
};

typedef std::vector<base::WeakPtr<WorkChannel> > WorkChannelVector;


}

#endif//_WORK_CHANNEL_954B90DE_3503_4C3D_B381_A23C60AA7C0E_